import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes, subFilterItem, topCategoryItem } from '@/types/data'
export default defineStore('category', {
  state: () => {
    return {
      topCategoryList: {} as topCategoryItem,
      subCategoryList: {} as subFilterItem,
    }
  },
  actions: {
    async getTopCategory(id: string) {
      const res = await request.get<ApiRes<topCategoryItem>>('/category', {
        params: { id },
      })
      // console.log(res)
      this.topCategoryList = res.data.result
    },
    // 筛选功能
    async getSubCategory(id: string) {
      const res = await request.get<ApiRes<subFilterItem>>('/category/sub/filter', {
        params: { id },
      })
      // console.log(res)
      this.subCategoryList = res.data.result
      // console.log(this.subCategoryList)
    },
  },
})
